package service

import (
	"reward-server/forms/request"
	"reward-server/forms/response"
	mq "reward-server/models/mysql"
)

type IWishWallService interface {
	Create(req request.WishWallReq) (err error)
	GetList(req request.WishSearchReq) (res *response.ListResp, err error)
}

type WishWallService struct {
	Wall mq.IWishingWall
}

func NewWishWallService() IWishWallService {

	return &WishWallService{
		Wall: mq.NewWishingWall(),
	}
}

func (s *WishWallService) Create(req request.WishWallReq) (err error) {
	err = s.Wall.Insert(&mq.WishingWall{
		Name:        req.Name,
		AccountAddr: req.AccountAddr,
		Description: req.Description,
	})
	return
}

func (s *WishWallService) GetList(req request.WishSearchReq) (res *response.ListResp, err error) {

	result, total, err := s.Wall.GetList(req)
	if err != nil {
		return nil, err
	}
	var data []*response.WishWall
	for _, v := range result {
		data = append(data, &response.WishWall{
			Id:          v.Id,
			Name:        v.Name,
			AccountAddr: v.AccountAddr,
			Description: v.Description,
		})
	}

	return &response.ListResp{
		Total: total,
		Data:  data,
	}, nil
}
